package ch.sfug.anim.tween.property {
	import flash.display.DisplayObject;
	
	import ch.sfug.anim.tween.CompositeTween;		

	/**
	 * @author loop
	 */
	public class Mover extends CompositeTween {

		public function Mover( d:DisplayObject, dur:uint ) {
			tween = new PropertyTween(d, dur);
		}
				/**
		 * moves the movieclip to a new position from the current
		 * @param x the target x position of the tween
		 * @param easeXBoth the easing function for the x movement and if no easeY is specified also for the y movement
		 * @param y the target y porition of the tween
		 * @param easeY the easing function for the y movement
		 */
		public function moveTo( x:Number, y:Number, easeXBoth:Function = null, easeY:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(x) ) obj[ "x" ] = { to: x, easing:easeXBoth };
			if( !isNaN(y) ) obj[ "y" ] = { to: y, easing:( easeY == null ) ? easeXBoth : easeY };
			PropertyTween( tween ).tween(obj);
		}
				/**
		 * moves the movieclip to a new x position
		 * @param x the new x position after the tween
		 * @param ease the easing function for the movement
		 */
		public function moveToX( x:Number, ease:Function = null ):void {
			var obj:Object = new Object();
			obj[ "x" ] = { to: x, easing: ease };
			PropertyTween( tween ).tween(obj);
		}
				/**
		 * moves the movieclip to a new y position
		 * @param x the new y position after the tween
		 * @param ease the easing function for the movement
		 */
		public function moveToY( y:Number, ease:Function = null ):void {
			var obj:Object = new Object();
			obj[ "y" ] = { to: y, easing: ease };
			PropertyTween( tween ).tween(obj);
		}
				/**
		 * moves the movieclip from a position to a position
		 * @param xfrom the start x position of the tween
		 * @param xto the end x position of the tween
		 * @param yfrom the start y position of the tween
		 * @param yto the end y position of the tween
		 * @param easeXBoth the easing function for the x movement and if no easeY is specified also for the y movement
		 * @param easeY the easing function for the y movement
		 */
		public function moveFromTo( xfrom:Number, xto:Number, yfrom:Number, yto:Number, easeXBoth:Function = null, easeY:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(xfrom) && !isNaN(xto) ) obj[ "x" ] = { from: xfrom, to: xto, easing:easeXBoth };
			if( !isNaN(yfrom) && !isNaN(yto) ) obj[ "y" ] = { from: yfrom, to: yto, easing:( easeY == null ) ? easeXBoth : easeY };
			PropertyTween( tween ).tween(obj);
		}
				/**
		 * moves the movieclip by an x amount and a y amount
		 * @param xamount the amount on which the x pos should be moved
		 * @param yamount the amount on which the y pos should be moved
		 * @param easeXBoth the easing function for the x movement and if no easeY is specified also for the y movement
		 * @param easeY the easing function for the y movement
		 */
		public function moveBy( xamount:Number, yamount:Number, easeXBoth:Function = null, easeY:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(xamount) && xamount != 0 ) obj[ "x" ] = { by: xamount, easing:easeXBoth };
			if( !isNaN(yamount) && yamount != 0 ) obj[ "y" ] = { by: yamount, easing:( easeY == null ) ? easeXBoth : easeY };
			PropertyTween( tween ).tween(obj);
		}
				/**
		 * sets the target the fade
		 */
		public function set target( d:DisplayObject ):void {
			tween.target = d;
		}
				/**
		 * returns the display object that fades
		 */
		public function get target(  ):DisplayObject {
			return DisplayObject(tween.target);
		}
				/**
		 * sets the duration of the mover
		 */
		public function set duration( n:Number ):void {
			tween.duration = n;
		}
		
		/**
		 * returns the duration of the mover
		 */
		public function get duration( ):Number {
			return tween.duration;
		}
				/**
		 * applies new x/y position
		 */
		public function apply( new_x:Number = NaN, new_y:Number = NaN ):void {
			var obj:Object = new Object();
			if( !isNaN(new_x) ) obj["x"] = new_x;
			if( !isNaN(new_y) ) obj["y"] = new_y;
			PropertyTween( tween ).apply(obj);
		}
	}
}
